#include "app_mqtt.h"
#include "cJSON/cJSON.h"
/**
 * @brief 消息接收回调函数
 * @param json 接收到的消息
 * @return int 1:成功 -1:失败
 */
int mqtt_rec_callback_function(char *json)
{
    cJSON *root = cJSON_Parse(json);
    if (root == NULL)
    {
        log_error("cJSON_Parse failed");
        return -1;
    }
    cJSON *conn_type = cJSON_GetObjectItem(root, "conn_type");
    cJSON *id = cJSON_GetObjectItem(root, "id");
    cJSON *msg = cJSON_GetObjectItem(root, "msg");
    if (conn_type == NULL || id == NULL || msg == NULL)
    {
        log_error("cJSON_GetObjectItem failed");
        return -1;
    }
    log_info("conn_type: %d", conn_type->valueint);
    log_info("id: %s", id->valuestring);
    log_info("msg: %s", msg->valuestring);

    cJSON_Delete(root);
    return 1;
}
int main(int argc, char const *argv[])
{
    app_mqtt_init();
    app_mqtt_register_recv_callback(mqtt_rec_callback_function);
    char *json_str = "{\"conn_type\":1,\"id\":\"5858\",\"msg\":\"61626364\"}";
    app_mqtt_send(json_str);


    while (1)
    {
        /* code */
    }
    
    return 0;
}
